home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / pthd-0.000 / pthd-0 / pthd-0.7 / src_signals / sigaction.c.1 < prev    next >
Encoding:
Text File  |  1995-08-16  |  732 b   |  46 lines

  1. /*
  2.  * sigaction.c.1
  3.  */
  4. #include <pthread.h>
  5. #include <stdio.h>
  6. #include "utils.h"
  7.  
  8. extern int getpid( void );
  9.  
  10. void
  11. handler( int sig )
  12. {
  13.     pthread_lock_global_np();
  14.     printf("Caught %s[%d]!\n", sys_signame[sig], sig );
  15.     pthread_unlock_global_np();
  16. }
  17.  
  18.  
  19. int main( int argc, char *argv[] )
  20. {
  21.    struct sigaction act;
  22.    struct timespec ts = { 0, 50000 };
  23.    int i, signo = NSIG;
  24.    
  25.    printf("pid %d\n", getpid());
  26.  
  27.    for(i = 1; i < NSIG; i++ )
  28.    {
  29.        if( i == 9 )
  30.            continue;
  31.        act.sa_handler = handler;
  32.        sigemptyset( &act.sa_mask );
  33.        pthread_sigaction_np( i, &act, NULL );
  34.    }
  35.  
  36.    while( signo-- > 0 )
  37.    {
  38.        pthread_delay_np( &ts );
  39.        pthread_kill( NULL, signo );
  40.    }
  41.  
  42.    print_str("success!");
  43.  
  44.    return(0);
  45. }
  46.